package com.project.demo.service.impi;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.demo.entity.Finance;
import com.project.demo.mapper.Financemapper;
import com.project.demo.service.FinanceService;
import com.project.demo.vo.AllFinanceVo;
import com.project.demo.vo.FinanceVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class FinanceServiceimpi implements FinanceService {
    @Autowired
    private Financemapper financemapper;

    @Override
    public FinanceVo<AllFinanceVo> FindFinanceVo(Integer page,Integer limit) {
        FinanceVo financeVo = new FinanceVo();
        financeVo.setCode(0);
        financeVo.setMsg("");
        IPage<Finance> financeIPage = new Page<>(page,limit);
        IPage<Finance>result =  financemapper.selectPage(financeIPage,null);
        financeVo.setCount(result.getTotal());
        List<Finance> financeList = result.getRecords();
        List<AllFinanceVo> allfinancevoList = new ArrayList<>();
        for (Finance finance1 : financeList) {
            AllFinanceVo allfinancevo = new AllFinanceVo();
            BeanUtils.copyProperties(finance1,allfinancevo);
            allfinancevoList.add(allfinancevo);
        }
        financeVo.setData(allfinancevoList);
        return financeVo;
    }
}
